package Messages;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * this class implements the librarian get lates report from db
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class GetLatesBooks {
	private ConnectionToClient client ;
/**
 * constractor of this class 
 * @param  get the client
 */
	public GetLatesBooks(ConnectionToClient client) {
		super();
        this.client = client;
	}


	public void Report(String[] str) {
		
		
            
            try 
            {
                    Statement stmt;
                    SQLConnection conn = new  SQLConnection();
                    stmt = conn.getConnection().createStatement();
                    
                    
                                    
                                    
                    ResultSet rs1=stmt.executeQuery("SELECT DISTINCT CopyId FROM db1.Lending  WHERE EndDate<ActualReturnDate AND ActualReturnDate >='"+str[1]+"' AND ActualReturnDate<='"+str[2]+"'AND ActualReturnDate<>'"+null+"';");
                    
                    ArrayList<Object> arr=new ArrayList<Object>();
                    arr.add("GetLatesBooks");
                                     try {
                                            if (rs1.next())
                                                    {
                                            		 rs1.previous();
                                                     while (rs1.next())
                                                     {	
                                                    	 arr.add(rs1.getString(1));
                                                     }
                                                   }
                                            
                            				client.sendToClient(arr);
                                    }
                                            catch (SQLException e)
                                                            {       
                                                            e.printStackTrace();
                                                            }
            					}

            					catch (Exception ex )
            					{
            						ex.printStackTrace();
            					}
            
   
	

}
	
}
